#include "stdafx.h"
#include "wf_modifyentity.h"

#include "pf_snapper.h"



WF_ModifyEntity::WF_ModifyEntity(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Modify Entity", container, graphicView) {

    en = NULL;
}


QAction* WF_ModifyEntity::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Properties")
    QAction* action = new QAction(tr("&Properties"), NULL);
	action->setIcon(QIcon(":/extui/modifyentity.png"));
    //action->zetStatusTip(tr("Modify Entity Properties"));
    return action;
}

void WF_ModifyEntity::trigger() {
    if (en!=NULL) {
        PF_Entity* clone = en->clone();
        if (PF_DIALOGFACTORY->requestModifyEntityDialog(clone)) {
            container->addEntity(clone);

            graphicView->deleteEntity(en);
			en->setSelected(false);

			clone->setSelected(false);
            graphicView->drawEntity(clone);

            if (document!=NULL) {
                document->startUndoCycle();

                document->addUndoable(clone);
                en->setUndoState(true);
                document->addUndoable(en);

                document->endUndoCycle();
            }
            PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
        } else {
            delete clone;
        }

    } else {
        PF_DEBUG->print("PF_ActionModifyEntity::trigger: Entity is NULL\n");
    }
}



void WF_ModifyEntity::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        en = catchEntity(e);
        trigger();
    }
}



void WF_ModifyEntity::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::SelectCursor);
}

// EOF
